<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>聚财通</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/fund.css"/>

    <script type="text/javascript" src='../../scripts/h5/zepto1.0.min.js'></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/zepto.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body style="background: #fff">
<div class="zz-writeMsg-jj">请输入短信验证码，用于确认验证。</div>

<table class="zz-table">
    <tr class="zz-msgVerify-jj">
        <td class="zz-msgVerify-1"></td>
        <td class="zz-msgVerify-2"></td>
        <td class="zz-msgVerify-3"></td>
        <td class="zz-msgVerify-4"></td>
        <td class="zz-msgVerify-5"></td>
        <td class="zz-msgVerify-6"></td>
    </tr>
</table>

<div class="zz-toastMsg-jj">请输入手机号<span id="payeeMobileId"></span>收到6位数字短信验证码</div>
<input type="button" class="zz-code-jj" value="获取验证码">
<div class="zz-box-jj" id="zz-box-jj">
    <ul class="zz-key-jj">
        <li>
            <p>1</p>
            <p>2</p>
            <p>3</p>
        </li>
        <li>
            <p>4</p>
            <p>5</p>
            <p>6</p>
        </li>
        <li>
            <p>7</p>
            <p>8</p>
            <p>9</p>
        </li>
        <li>
            <p class="zz-kongbai-jj"></p>
            <p>0</p>
            <p class="zz-delete-jj"></p>
        </li>
    </ul>
</div>

</body>
<script type="text/javascript" src='../../scripts/h5/fastClick.js'></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>

<script>
    var queryURLParameter = utils.queryURLParameter();
    var page = queryURLParameter.page;
    var origAmt = queryURLParameter.origAmt;
    var isFast = queryURLParameter.isFast;
	var mobileId = queryURLParameter.mobileId;
	
    var $msgVerify_1 = $(".zz-msgVerify-1");
    var $msgVerify_2 = $(".zz-msgVerify-2");
    var $msgVerify_3 = $(".zz-msgVerify-3");
    var $msgVerify_4 = $(".zz-msgVerify-4");
    var $msgVerify_5 = $(".zz-msgVerify-5");
    var $msgVerify_6 = $(".zz-msgVerify-6");
    var $payeeMobileId = $("#payeeMobileId");
    var $code = $(".zz-code-jj");
    var payeeMobileId = "";
    var verifyCode = "";
    
    FastClick.attach(document.body);
    
	if(mobileId != undefined){
		payeeMobileId = mobileId;
		$payeeMobileId.html(payeeMobileId.slice(0, 3) + "****" + payeeMobileId.slice(7, 11));
		send($code)
	} else {
	    $.ajax({
	        url: utils.ajaxUrl()+"h5/settlementController/queryPayee",
	        async: false,
	        type: 'get',
	        success: function (res) {
	            var res = JSON.parse(res);
	            console.log(res);
	            if (res && res.retCode == '0000') {
	                payeeMobileId = res.storeInf.payeeMobileId;
	                $payeeMobileId.html(payeeMobileId.slice(0, 3) + "****" + payeeMobileId.slice(7, 11));
	                console.log(payeeMobileId);
	                send($code)
	            } else {
	                utils.error("sx.png", "啊哦，数据异常");
	            }
	        },
	        error: function () {
	            utils.error("wlyc.png", "啊哦，连接不到网络呢");
	        }
	    });
    }

    $code.click(function () {
        var that = $(this);
        send(that)
    });

    function send(that) {
        $.ajax({
            url: utils.ajaxUrl()+"h5/settlementController/send",
            async: false,
            data: {
                bankMobileId: payeeMobileId
            },
            type: 'get',
            success: function (res) {
                var res = JSON.parse(res);
                console.log(res);
                if (res && res.retCode == '0000') {
                    utils.time(that, 1);
                } else {
                    utils.error("sx.png", "啊哦，数据异常");
                }
            },
            error: function () {
                utils.error("wlyc.png", "啊哦，连接不到网络呢");
            }
        });
    }

    var index = 0;
    $(".zz-key-jj").on("tap", "p", function () {
        var $this = $(this);
        if ($this.hasClass('zz-kongbai-jj')) {
            return false
        }

        if ($this.hasClass('zz-delete-jj')) {
            console.log(index);
            if (index == 0) {
                return false;
            }

            switch (index) {
                case 1:
                    $msgVerify_1.html("");
                    break;
                case 2:
                    $msgVerify_2.html("");
                    break;
                case 3:
                    $msgVerify_3.html("");
                    break;
                case 4:
                    $msgVerify_4.html("");
                    break;
                case 5:
                    $msgVerify_5.html("");
                    break;
                case 6:
                    $msgVerify_6.html("");
                    break;
                default:
                    index = 0;
                    return false
            }
            index--;
            verifyCode = "";
            return
        }
        index++;

        switch (index) {
            case 1:
                $msgVerify_1.html($this.html());
                break;
            case 2:
                $msgVerify_2.html($this.html());
                break;
            case 3:
                $msgVerify_3.html($this.html());
                break;
            case 4:
                $msgVerify_4.html($this.html());
                break;
            case 5:
                $msgVerify_5.html($this.html());
                break;
            case 6:
                $msgVerify_6.html($this.html());
                break;
            default:
                index = 6;
        }

        if (index == 6) {
            $msgVerify_6.html($this.html());

            utils.newModalAnimationShow("验证中");
            $(".zz-msgVerify-jj td").each(function () {
                verifyCode = verifyCode + $(this).html();
            });
            verifyCode = verifyCode.slice(0, 6);
            console.log(verifyCode);
            if (page == "fundOpenBalance") {
                setTimeout(function () {
                    $.ajax({
                        url: utils.ajaxUrl()+"h5/openFundController/openFund",
                        async: false,
                        data: {
                            mobileNo: payeeMobileId,
                            verifyCode: verifyCode
                        },
                        type: 'get',
                        success: function (res) {
                            var res = JSON.parse(res);
                            console.log(res);
                            if (res && res.retCode == '0000') {
                                window.location.href = "../../html/h5/success.html?success=fundMsgVerify";
                            } else if (res.retCode == '00060700') {
                                utils.newModalPrompt("验证码输入错误");
                                $(".zz-msgVerify-jj td").html("");
                                utils.newModalAnimationHide(0);
                                index = 0;
                                verifyCode = "";
                            } else {
                                window.location.href = "../../html/h5/errorPage.html";
                                //utils.error("sx.png", "啊哦，数据异常");
                            }
                        },
                        error: function () {
                            utils.error("wlyc.png", "啊哦，连接不到网络呢");
                        }
                    });
                }, 200)
            }
            if (page == "fundRollOut") {
                setTimeout(function () {
                    $.ajax({
                        url: utils.ajaxUrl()+"h5/fund/opendAccount/userPurchase",
                        async: false,
                        data: {
                            mobileId: payeeMobileId,
                            verifyCode: verifyCode,
                            isFast: isFast,
                            origAmt: origAmt
                        },
                        type: 'get',
                        success: function (res) {
                            var res = JSON.parse(res);
                            console.log(res);
                            if (res && res.retCode == '0000') {
                                window.location.href = "../../html/h5/successApply.html?applicationTime="+res.applicationTime+"&tradeTime="+res.tradeTime+"&origAmt="+origAmt;
                            } else if (res.retCode == '00060700') {
                                utils.newModalPrompt("验证码输入错误");
                                $(".zz-msgVerify-jj td").html("");
                                utils.newModalAnimationHide(0);
                                index = 0;
                                verifyCode = "";
                            } else {
                                window.location.href = "../../html/h5/errorApply.html?applicationTime="+res.applicationTime+"&tradeTime="+res.tradeTime+"&origAmt="+origAmt;
                                //utils.error("sx.png", "啊哦，数据异常");
                            }
                        },
                        error: function () {
                            utils.error("wlyc.png", "啊哦，连接不到网络呢");
                        }
                    });
                }, 200)
            }
        }
    })

</script>
</html>